//
//  RadioViewController.m
//  Leisure
//
//  Created by xalo on 16/6/30.
//  Copyright © 2016年 张凡. All rights reserved.
//

#import "RadioViewController.h"

@interface RadioViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong)NSMutableArray *scrollArray;
@property (nonatomic, strong)NSMutableArray *dataArray;

@end

@implementation RadioViewController

- (NSMutableArray *)dataArray{
    
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

- (NSMutableArray *)scrollArray{
    
    if (!_scrollArray) {
        _scrollArray = [NSMutableArray array];
    }
    return _scrollArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    
    
    [RequsetManager fetchDataWithUrl:kRadioUrl parametr:@{} mehtod:@"POST" complete:^(NSData *data) {
        
        NSDictionary *bigDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        NSLog(@"%@", bigDic);
        for (NSDictionary *smallDic in bigDic[@"data"][@"carousel"]) {
            [self.scrollArray addObject:smallDic[@"img"]];
        }
        for (NSDictionary *smallDic in bigDic[@"data"][@"alllist"]) {
            RadioModel *radioModal = [[RadioModel alloc] init];
            [radioModal setValuesForKeysWithDictionary:smallDic];
            [self.dataArray addObject:radioModal];
        }
    } updateUI:^{
        
        [self.tableView reloadData];
        //创建轮播图
        
        ZFScrollView *headerView = [[ZFScrollView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight/3) imageArray:self.scrollArray];
        self.tableView.tableHeaderView = headerView;
    }];
}

#pragma mark ------UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.textLabel.text = [self.dataArray[indexPath.row] title];
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
